import numpy as np

def simulation_data(N,I,ab_p):
    """根据作答时间模型，生成作答

    Args:
        N (int): 被试人数
        I (int): 题目个数
        ab_p (float): 异常作答比例

    Returns:
        list: [正常作答时间,[随机作答RT,加速作答RT,极短作答RT],[随机作答flag,加速作答flag,极短作答flag]]
    """
    lambda_i = np.random.normal(4,0.25,size=(1,I))
    phi_i = np.random.normal(1,0.17*0.5,size=(1,I))
    zeta_p = np.random.normal(0,1,size=(N,1))
    epsilon = 1/np.random.uniform(1,5,size=(1,I))
    rt = np.random.lognormal(phi_i*(lambda_i-zeta_p),epsilon)

    ## random 随机作答
    random_flag = np.random.binomial(1,ab_p,(N,1))
    random_rt = np.random.normal(4,1,size=(N,I))*random_flag+rt*(1-random_flag)
    ## speedness 加速作答
    zeta_p_speedness = np.random.normal(1.5,1,size=(N,1))
    speedness_flag_p = np.random.binomial(1,ab_p,(N,1))
    speedness_flag = speedness_flag_p*np.random.binomial(1,0.5,(N,I))
    speedness_rt = np.random.lognormal(phi_i*(lambda_i-zeta_p_speedness),epsilon**0.5)*speedness_flag+\
                    rt*(1-speedness_flag)
    ## extrme 极端作答
    extrme_flag_p = np.random.binomial(1,ab_p,(N,1))
    extrme_flag = extrme_flag_p*(np.random.randint(0,I,(N,1))==np.arange(I))
    extrme_rt = lambda_i.max()*2*extrme_flag+rt*(1-extrme_flag)
    return [rt,[random_rt,speedness_rt,extrme_rt],[random_flag,speedness_flag_p,extrme_flag_p]]